import axios from 'axios';
import { defineStore } from 'pinia';

const getAuth = () => axios.get('/api/common/auth', {
  headers: {
    appid: 'honkai.impact.star:rail-lightcone',
  },
});

interface State {
  account: string;
  roles: string[];
  permissions: string[];
}
const useAuthStore = defineStore('auth', {
  state: () => ({
    account: '',
    roles: [],
    permissions: [],
  } as State),
  actions: {
    handleInit() {
      return getAuth().then(({ data }) => {
        this.account = data?.data?.account || '';
        this.roles = data?.data?.roles || [];
        this.permissions = data?.data?.permissions || [];
      });
    },
  },
});

export default useAuthStore;
